/**
 @file ctc_asw_l2.h

 @author  Copyright (C) 2020 Centec Networks Inc.  All rights reserved.

 @date 2020-06-15

 @version v1.0

The module provides L2UC/L2MC/management functions.
\p
1) L2UC operation
\p
 When creating a new L2 entry, you need three information: MAC/FID/destination information.
 The Forwarding Instance ID (FID) is wide concept in the CTC SDK. As the L2 forwarding look up is based on MAC+FID  in the Module,
 the basic information of the packet such as VLAN value, VSI value should be mapped to the FID before further operation. Up to 128 FIDs
 are supported in the Module. Several mappings to FID can be done and are described as followed.
\p
    VLAN mapping to FID in 802.1D VLAN bridge
\d        One to one mapping of VLAN ID and FID in IVL bridge
\d        Many to one mapping of VLAN ID and FID in SVL bridge
\p
    S+C/S/C mapping to FID (VLAN mapping)
\p
 The allocation of the FID is in high-level application, below is an example for the allocation of FID.
\p

\t   |      Type                |  Number     |   FID         |
\t   |--------------------------|-------------|---------------|
\t   |  802.1q bridge           |      4k     | 0~4095        |
\t   |--------------------------|-------------|---------------|
\p
\p
The destination information in ctc_l2_addr_t can either be the gport. generally, basic bridge will use ctc_l2_add_fdb()
  to add a MAC address to FDB table with the given FID and the given port.
  If the sent packet need do packet edit from the given port.
\b
2) L2MC and default entry operation
\p
 When creating a new L2MC group , you need three information: Multicast MAC/FID and the search key
 is the Multicast MAC  + FID.
 In The Module, L2MC,VLAN based broadcast and VSI based broadcast are using multicast replication, and
 each multicast group has a value to identify it. In Centec chipset,
 multicast entries are stored in mc_table which is organized as link list.
 \p
\S ctc_l2.h:ctc_l2_flag_t
\S ctc_l2.h:ctc_l2_addr_t
\S ctc_l2.h:ctc_l2_mcast_addr_t
*/
#ifndef _CTC_ASW_L2_H
#define _CTC_ASW_L2_H
#ifdef __cplusplus
extern "C" {
#endif

/**********************************************************************************
                      Define API function interfaces
***********************************************************************************/

/**
 @brief Init fdb module

 @param[in] lchip    local chip id

 @param[in]  l2_fdb_global_cfg l2 fdb global config information

 @remark[TMA] Initialize the The Module fdb subsystem, including global variable, soft table, asic table, etc.

 @return CTC_E_XXX

*/
extern int32
ctc_asw_l2_fdb_init(uint8 lchip, void* l2_fdb_global_cfg);

/**
 @brief De-Initialize l2 module

 @param[in] lchip    local chip id

 @remark[TMA]  User can de-initialize the l2 configuration

 @return CTC_E_XXX
*/
extern int32
ctc_asw_l2_fdb_deinit(uint8 lchip);

/**
 @brief Add a fdb entry

 @param[in] lchip    local chip id

 @param[in] l2_addr       device-independent L2 unicast address

 @remark[TMA]  Add a MAC address to FDB table with the given FID and parameters.

 @return CTC_E_XXX

*/
extern int32
ctc_asw_l2_add_fdb(uint8 lchip, ctc_l2_addr_t* l2_addr);
/**
 @brief Remove a fdb entry

 @param[in] lchip    local chip id

 @param[in] l2_addr      device-independent L2 unicast address

 @remark[TMA]  Delete the given MAC address with the specified FID from the device.

 @return CTC_E_XXX

*/
extern int32
ctc_asw_l2_remove_fdb(uint8 lchip, ctc_l2_addr_t* l2_addr);
/**
 @brief Create a layer2 multicast group

 @param[in] lchip    local chip id

 @param[in] l2mc_addr     l2MC  data structure

 @remark[TMA]  Add the given MAC address with the specified FID from the device.

 @return CTC_E_XXX

*/
extern int32
ctc_asw_l2mcast_add_addr(uint8 lchip, ctc_l2_mcast_addr_t* l2mc_addr);

/**
 @brief This Remove a layer2 multicast group

 @param[in] lchip    local chip id

 @param[in] l2mc_addr     l2MC  data structure

 @remark[TMA]   Remove a layer2 multicast group with MAC/FID.

 @return CTC_E_XXX

*/
extern int32
ctc_asw_l2mcast_remove_addr(uint8 lchip, ctc_l2_mcast_addr_t* l2mc_addr);

/**
 @brief Add a member port into a existed multicast group

 @param[in] lchip    local chip id

 @param[in] l2mc_addr     l2MC  data structure

 @remark[TMA]  Add member to an existing entry corresponding to the multicast address/VLAN ID in the multicast group.

 @return CTC_E_XXX

*/
extern int32
ctc_asw_l2mcast_add_member(uint8 lchip, ctc_l2_mcast_addr_t* l2mc_addr);

/**
 @brief Remove a member port into a existed multicast group

 @param[in] lchip    local chip id

 @param[in] l2mc_addr     l2MC  data structure

 @remark[TMA]  Remove member from an existing entry corresponding to the multicast address/VLAN ID in the multicast group.

 @return CTC_E_XXX

*/
extern int32
ctc_asw_l2mcast_remove_member(uint8 lchip, ctc_l2_mcast_addr_t* l2mc_addr);

/**
 @brief Flush fdb entry by specified type(based on mac, port, fid) and specified flag(static,dynamic,all)

 @param[in] lchip    local chip id

 @param[in] pFlush      flush FDB entries data structure

 @remark[TMA]   flush all fdb entries according to the given flush condition.
           The flush condition include  the query type ctc_l2_flush_fdb_flag_t
           and the query flag ctc_l2_flush_fdb_flag_t.

 @return CTC_E_XXX

*/
extern int32
ctc_asw_l2_flush_fdb(uint8 lchip, ctc_l2_flush_fdb_t* pFlush);

/**
 @brief Get fdb count according to specified query condition

 @param[in] lchip    local chip id

 @param[in|out] pQuery   query condition

 @remark[TMA]   Get fdb count according to the given query condition,only support get learning count.

 @return CTC_E_XXX

*/
extern int32
ctc_asw_l2_get_fdb_count(uint8 lchip,  ctc_l2_fdb_query_t* pQuery);

/**
 @brief Query fdb enery according to specified query condition

 @param[in] lchip    local chip id

 @param[in] pQuery           query condition

 @param[in|out] query_rst  query results

 @remark[TMA]   Query all fdb entries according to the given query condition.
           The query condition include  the query type ctc_l2_fdb_query_type_t
           and the query flag ctc_l2_fdb_query_flag_t.\p

\d           If it is the first query,  query_rst.start_index must be equal to 0,
               else must is equal to the last next_query_index;
\d           If query_rst.is_end == 1,indicate the end of query.

 @return CTC_E_XXX

*/
extern int32
ctc_asw_l2_get_fdb_entry(uint8 lchip, ctc_l2_fdb_query_t* pQuery, ctc_l2_fdb_query_rst_t* query_rst);

/**
 @brief Set various properties of the fid

 @param[in] lchip    local chip id

 @param[in] fid_id          fid id

 @param[in] property        fid property

 @param[in] value           value need set

 @remark[TMA]
        Set property configuration as enum ctc_l2_fid_property_t with the uint32 value in the fid given.\p

 @return CTC_E_XXX
*/
extern int32
ctc_asw_l2_set_fid_property(uint8 lchip, uint16 fid_id, ctc_l2_fid_property_t property, uint32 value);

/**
 @brief Get various properties of the fid

 @param[in] lchip    local chip id

 @param[in] fid_id          fid id

 @param[in] property        fid property

 @param[out] value           value need get

 @remark[TMA]
        Get info about property configuration of this fid.

 @return CTC_E_XXX
*/
extern int32
ctc_asw_l2_get_fid_property(uint8 lchip, uint16 fid_id, ctc_l2_fid_property_t property, uint32* value);

#ifdef __cplusplus
}
#endif

#endif

